//创建微服务

const express = require('express')
const cors = require('cors')
//导入自定义的接口路由模块
const apiRouter = require('./router/user');
const app = express();

//定义jsonp接口
app.get('/api/jsonp', (req, res) => {
    //1.获取客户端发送过来的回调函数的名字
    const funNmae = req.query.callback;
    //2. 
    const data = {
        name: '张三',
        age: 80
    }
    const Str = `${funNmae}(${JSON.stringify(data)})`;
    res.send(Str);
})
app.use(cors());
app.use(function (req, res, next) {
    //设置响应头要放在cors后面，设置跨域只允许域名http://127.0.0.1:5500使用
    res.setHeader('Access-Control-Allow-Origin', '*');
    next();
})
app.use(express.urlencoded({ extended: false }))
app.use('/api', apiRouter);
app.listen(89, () => {
    console.log('127.0.0.1:89');

})